package com.kaishengit.service;

import org.hibernate.Query;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.UserDao;
import com.kaishengit.dao.UserGroupDao;
import com.kaishengit.pojo.User;
import com.kaishengit.pojo.UserGroup;

@Transactional
public class UserService {
    private UserDao userDao;
    private UserGroupDao userGroupDao;
    
    public User findById(String id) {
        return userDao.get(id);
    }

    public int emailCount(String email) {
        String hql = "select count(*) from User where email = ?";
        Query query = userDao.getSession().createQuery(hql);
        query.setParameter(0, email);
        int count=((Number)query.iterate().next()).intValue();
        return count;
    }
    
    public void save(User user) {
        userDao.save(user);
    }
    
    public UserGroup findUserGroupById(String id) {
        return userGroupDao.get(id);
    }
    
    //get set
    public UserDao getUserDao() {
        return userDao;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public UserGroupDao getUserGroupDao() {
        return userGroupDao;
    }

    public void setUserGroupDao(UserGroupDao userGroupDao) {
        this.userGroupDao = userGroupDao;
    }
}
